<template>
	<uni-search-bar @confirm="toSearch" placeholder="请输入搜索的公交地铁路线" v-model="searchKey"></uni-search-bar>
	<swiper style="height: 200px;" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
		<swiper-item v-for="(item,index) in lunboList" :key="index">
			<view class="swiper-item">
				<image style="width: 100%;" :src="item.URL" mode=""></image>
			</view>
		</swiper-item>
	</swiper>
</template>

<script setup>
	import { onLoad } from "@dcloudio/uni-app"
	import { ref } from "vue";
	import { CONFIG } from "../../utils/config";
	import { userStore } from "../../store/userStore.js"
	import { getMapDistance } from "../../utils/tools.js";
	
	const store = userStore()
	const searchKey = ref("")
	
	function toSearch()
			{
			    // console.log("search")
				if (searchKey.value == "") {
				    uni.showToast({
				        title: "请输入查询的公交地图线路",
				        icon: "none"
				    })
				} else {
				    window.location.href = `https://uri.amap.com/line?name=${searchKey.value}&city=029&callnative=0`
				}
			}
	 onLoad(()=>{
		 getLunbo()
		 getCurrentPos()
	 })
	 
	 const lunboList = ref([])
	 async function getLunbo(){
		 let res = await uni.$get(CONFIG.leanCloud_url+"/1.1/classes/Icon")
		 if(res.statusCode==200){
			 lunboList.value = res.data.results
		 }
		 console.log(lunboList.value)
	 }
	 
	 
	function getCurrentPos(){
		console.log("s111")
		 uni.getLocation({
		 	success: function(res){
				console.log("当前的经度："+res.longitude)
				console.log("当前的纬度："+res.latitude)
				store.setPos(res.longitude,res.latitude)
			},
			fail(err) {
				console.log()
			}
		 })
	 }
	 
</script>

<style lang="scss" scoped>
	
</style>